package com.example.demo.mapper;/**
 * ClassName: TimeSlotAvailability
 * Package: com.example.demo.mapper
 * Description:
 *
 * @Author 理理
 * @Create 2025/3/2 18:13
 * @Version 1.0
 */

import com.example.demo.entity.TimeSlotAvailability;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.sql.Date;
import java.util.List;

/**
 *
 *@title: TimeSlotAvailability
 *@Author: Tangerine
 *@Date: 2025/3/2 18:13
 *@version 1.0
 */
@Mapper
public interface TimeSlotAvailabilityMapper {

    //查询已确认的预约数量（即预约成功）
    @Select("select tq.id as timeSlot,s.date, sum(case when s.type='班级预约' then 1 else 0 end) as team, sum(case when s.type='个人预约' then 1 else 0 end) as personal, c.count from timequantum tq left join subscribe s on tq.id = s.time and s.classes_name=#{classes_name} and s.date between #{start_date} and #{end_date} and s.state='预约成功' left join classes c on c.name=#{classes_name} group by tq.id, s.date")
    List<TimeSlotAvailability> confirm(@Param("classes_name") String classes_name, @Param("start_date") Date start_date, @Param("end_date") Date end_date);

    //个人预约判断
    @Select("select tq.id as timeSlot,s.date, sum(case when s.type='班级预约' then 1 else 0 end) as team, sum(case when s.type='个人预约' then 1 else 0 end) as personal, c.count from timequantum tq left join subscribe s on tq.id = s.time and s.classes_name=#{classes_name} and s.date=#{date} and s.state='预约成功' left join classes c on c.name=#{classes_name} where tq.id=#{time} group by tq.id, s.date")
    TimeSlotAvailability con(@Param("classes_name") String classes_name, @Param("date") Date start_date,@Param("time") int time);
}
